.TH std::is_invocable,std::is_invocable_r,std::is_nothrow_invocable, 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::is_invocable,std::is_invocable_r,std::is_nothrow_invocable, \- std::is_invocable,std::is_invocable_r,std::is_nothrow_invocable,

.SH Synopsis

   Defined in header <type_traits>
   template< class Fn, class... ArgTypes >          \fB(1)\fP \fI(since C++17)\fP
   struct is_invocable;
   template< class R, class Fn, class... ArgTypes > \fB(2)\fP \fI(since C++17)\fP
   struct is_invocable_r;
   template< class Fn, class... ArgTypes >          \fB(3)\fP \fI(since C++17)\fP
   struct is_nothrow_invocable;
   template< class R, class Fn, class... ArgTypes > \fB(4)\fP \fI(since C++17)\fP
   struct is_nothrow_invocable_r;

   1) Determines whether INVOKE(std::declval<Fn>(), std::declval<ArgTypes>()...) is
   well formed when treated as an unevaluated operand.
   2) Determines whether INVOKE<R>(std::declval<Fn>(), std::declval<ArgTypes>()...) is
   well formed when treated as an unevaluated operand.
   3) Determines whether INVOKE(std::declval<Fn>(), std::declval<ArgTypes>()...) is
   well formed when treated as an unevaluated operand, and is known not to throw any
   exceptions.
   4) Determines whether INVOKE<R>(std::declval<Fn>(), std::declval<ArgTypes>()...) is
   well formed when treated as an unevaluated operand, and is known not to throw any
   exceptions.

   If Fn, R or any type in the parameter pack ArgTypes is not a complete type,
   (possibly cv-qualified) void, or an array of unknown bound, the behavior is
   undefined.

   If an instantiation of a template above depends, directly or indirectly, on an
   incomplete type, and that instantiation could yield a different result if that type
   were hypothetically completed, the behavior is undefined.

   If the program adds specializations for any of the templates described on this page,
   the behavior is undefined.

.SH Member constants

            true if (for overload \fB(1)\fP) INVOKE(std::declval<Fn>(),
   value    std::declval<ArgTypes>()...) is well formed when treated as an unevaluated
   \fB[static]\fP operand, false otherwise
            \fI(public static member constant)\fP

.SH Member functions

   operator bool converts the object to bool, returns value
                 \fI(public member function)\fP
   operator()    returns value
   \fI(C++14)\fP       \fI(public member function)\fP

.SH Member types

   Type       Definition
   value_type bool
   type       std::integral_constant<bool, value>

.SH Notes

     Feature-test macro    Value    Std                  Feature
   __cpp_lib_is_invocable 201703L \fI(C++17)\fP std::is_invocable, std::invoke_result

.SH Examples


// Run this code

 #include <type_traits>

 auto func2(char) -> int (*)()
 {
     return nullptr;
 }

 int main()
 {
     static_assert(std::is_invocable_v<int()>);
     static_assert(not std::is_invocable_v<int(), int>);
     static_assert(std::is_invocable_r_v<int, int()>);
     static_assert(not std::is_invocable_r_v<int*, int()>);
     static_assert(std::is_invocable_r_v<void, void(int), int>);
     static_assert(not std::is_invocable_r_v<void, void(int), void>);
     static_assert(std::is_invocable_r_v<int(*)(), decltype(func2), char>);
     static_assert(not std::is_invocable_r_v<int(*)(), decltype(func2), void>);
 }

.SH See also

   invoke                    invokes any Callable object with given arguments
   invoke_r                  and possibility to specify return type
   \fI(C++17)\fP                   (since C++23)
   (C++23)                   \fI(function template)\fP
   result_of                 deduces the result type of invoking a callable object with
   invoke_result             a set of arguments
   \fI(C++11)\fP(removed in C++20) \fI(class template)\fP
   \fI(C++17)\fP
   declval                   obtains a reference to its argument for use in unevaluated
   \fI(C++11)\fP                   context
                             \fI(function template)\fP
   invocable                 specifies that a callable type can be invoked with a given
   regular_invocable         set of argument types
   (C++20)                   (concept)
